home *** CD-ROM | disk | FTP | other *** search
- /* EditText.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
- #include <stdlib.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "Dispatcher.h"
- #include "DDocData.h"
- #include "EverythingEngine.h"
- #include "EverythingDoc.h"
- #include "EditText.h"
-
-
- static EverythingEngine* GetEngine (EditText* self);
-
- static void DoUndo (EditText* self);
- static void DoCut (EditText* self);
- static void DoCopy (EditText* self);
- static void DoPaste (EditText* self);
- static void DoClear (EditText* self);
- static void DoSelectAll (EditText* self);
- static void DoShowClipboard (EditText* self);
-
-
- //----------
- EditText* NewEditText ()
- {
- EditText* window;
-
- window = (EditText*)malloc (sizeof (EditText));
- EditText_Init (window);
- SetClassID (window, classEditText);
-
- return window;
- }
-
- //----------
- void DeleteEditText (
- EditText* window)
- {
- EditText_Free (window);
- free (window);
- }
-
- //----------
- void EditText_Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- EditText* winObj = NewEditText ();
-
- if (winObj != nil) {
- EditText_Open (winObj, inDoc, inData);
- }
- }
-
- //----------
- void EditText_Init (
- EditText* self)
- {
- }
-
- //----------
- void EditText_Free (
- EditText* self)
- {
- }
-
- //----------
- EverythingEngine* GetEngine (
- EditText* self)
- {
- return (EverythingEngine*) self->super.mDoc->mEngine;
- }
-
- /*----------*/
- void EditText_Open (
- EditText* self,
- AMDoc* inDoc,
- DDocData* inData)
- {
- WindowPtr window;
- Handle wftb;
-
- self->super.mDoc = inDoc;
- self->mData = inData;
- AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- window = GetNewCWindow (WIND_EditText, nil, (WindowPtr) -1L);
- if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
- SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
- }
- self->super.mWindow = window;
- ((EverythingDoc*)self->super.mDoc)->mEditTextPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) self);
- SetPort (window);
- SetInfo (window);
-
- wftb = GetResource ('Wftb', WIND_EditText);
-
- CreateRootControl (window, &self->super.mRootControl);
-
- self->super.vScroll = nil;
- self->super.hScroll = nil;
-
-
- self->mSmallHandle = GetNewControl (CNTL_Small, window);
- SetWindowItemFont (self->mSmallHandle, wftb, 1);
- SetControlTextStr (self->mSmallHandle, GetSmall (self->mData));
-
- self->mLargeHandle = GetNewControl (CNTL_Large, window);
- SetWindowItemFont (self->mLargeHandle, wftb, 2);
- SetControlTextStr (self->mLargeHandle, GetLarge (self->mData));
-
- self->mX12345Handle = GetNewControl (CNTL_X12345, window);
- SetWindowItemFont (self->mX12345Handle, wftb, 3);
- SetControlTextValue (self->mX12345Handle, GetX12345 (self->mData));
-
- self->mX12345e6Handle = GetNewControl (CNTL_X12345e6, window);
- SetWindowItemFont (self->mX12345e6Handle, wftb, 4);
- SetControlTextFloat (self->mX12345e6Handle, GetX12345e6 (self->mData));
-
- self->mPasswordHandle = GetNewControl (CNTL_Password, window);
- SetWindowItemFont (self->mPasswordHandle, wftb, 5);
- SetControlTextStr (self->mPasswordHandle, GetPassword (self->mData));
-
- self->mDateHandle = GetNewControl (CNTL_Date, window);
- SetWindowItemFont (self->mDateHandle, wftb, 6);
- SetClockDateTime (self->mDateHandle, GetTheDate (self->mData));
-
- self->mTimeHandle = GetNewControl (CNTL_Time, window);
- SetWindowItemFont (self->mTimeHandle, wftb, 7);
- SetClockDateTime (self->mTimeHandle, GetTheTime (self->mData));
-
- self->mStyledHandle = GetNewControl (CNTL_Styled, window);
- SetWindowItemFont (self->mStyledHandle, wftb, 8);
- SetControlTextStr (self->mStyledHandle, GetStyled (self->mData));
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- /*----------*/
- void EditText_Close (
- EditText* self)
- {
- RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- ((EverythingDoc*)self->super.mDoc)->mEditTextPtr = nil;
- SetInfo (nil);
- HideWindow (self->super.mWindow);
- DisposeWindow (self->super.mWindow);
-
- DeleteEditText (self);
- }
-
- /*----------*/
- void EditText_Track (
- EditText* self,
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- if (whichControl == self->mSmallHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mSmallHandle, where);
- }
- if (whichControl == self->mLargeHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mLargeHandle, where);
- }
- if (whichControl == self->mX12345Handle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mX12345Handle, where);
- }
- if (whichControl == self->mX12345e6Handle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mX12345e6Handle, where);
- }
- if (whichControl == self->mPasswordHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mPasswordHandle, where);
- }
- if (whichControl == self->mDateHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mDateHandle, where);
- }
- if (whichControl == self->mTimeHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mTimeHandle, where);
- }
- if (whichControl == self->mStyledHandle) {
- AMWindow_HandleEditClick ((AMWindow*) self, self->mStyledHandle, where);
- }
- }
-
- //----------
- void EditText_DataChanged (
- EditText* self,
- long inDataID)
- {
- if (inDataID == idSmall) {
- SetControlTextStr (self->mSmallHandle, GetSmall (self->mData));
- }
- if (inDataID == idLarge) {
- SetControlTextStr (self->mLargeHandle, GetLarge (self->mData));
- }
- if (inDataID == idX12345) {
- SetControlTextValue (self->mX12345Handle, GetX12345 (self->mData));
- }
- if (inDataID == idX12345e6) {
- SetControlTextFloat (self->mX12345e6Handle, GetX12345e6 (self->mData));
- }
- if (inDataID == idPassword) {
- SetControlTextStr (self->mPasswordHandle, GetPassword (self->mData));
- }
- if (inDataID == idTheDate) {
- SetClockDateTime (self->mDateHandle, GetTheDate (self->mData));
- }
- if (inDataID == idTheTime) {
- SetClockDateTime (self->mTimeHandle, GetTheTime (self->mData));
- }
- if (inDataID == idStyled) {
- SetControlTextStr (self->mStyledHandle, GetStyled (self->mData));
- }
- }
-
- /*----------*/
- void EditText_MouseIn (
- EditText* self,
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void EditText_ExitCurField (
- EditText* self)
- {
- ControlHandle focus;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- } else if (focus == self->mSmallHandle) {
- SetSmallHandle (self->mData, GetEditTextChars (self->mSmallHandle));
- } else if (focus == self->mLargeHandle) {
- SetLargeHandle (self->mData, GetEditTextChars (self->mLargeHandle));
- } else if (focus == self->mX12345Handle) {
- SetX12345 (self->mData, GetControlTextValue (self->mX12345Handle));
- } else if (focus == self->mX12345e6Handle) {
- SetX12345e6 (self->mData, GetControlTextFloat (self->mX12345e6Handle));
- } else if (focus == self->mPasswordHandle) {
- SetPasswordHandle (self->mData, GetEditTextChars (self->mPasswordHandle));
- } else if (focus == self->mDateHandle) {
- SetTheDate (self->mData, GetClockDateTime (self->mDateHandle));
- } else if (focus == self->mTimeHandle) {
- SetTheTime (self->mData, GetClockDateTime (self->mTimeHandle));
- } else if (focus == self->mStyledHandle) {
- SetStyledHandle (self->mData, GetEditTextChars (self->mStyledHandle));
- }
- }
-
- /*----------*/
- void EditText_TypeIn (
- EditText* self,
- char ch)
- {
- ControlHandle focus;
- short keyCode;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- EditText_ExitCurField (self); // Dispatch
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = curEvent.message & keyCodeMask;
- HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- } else {
- SysBeep (1);
- }
- }
-
- /*----------*/
- void EditText_Resize (
- EditText* self)
- {
- /* application-specific code to resize items in window */
- }
-
- /*----------*/
- void EditText_Scroll (
- EditText* self,
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == self->super.vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void DoUndo (
- EditText* self)
- {
- } // DoUndo
-
- //----------
- void DoCut (
- EditText* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECut (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void DoCopy (
- EditText* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void DoPaste (
- EditText* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEPaste (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoPaste
-
- //----------
- void DoClear (
- EditText* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEDelete (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoClear
-
- //----------
- void DoSelectAll (
- EditText* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void DoShowClipboard (
- EditText* self)
- {
- } // DoShowClipboard
-
- //----------
- Boolean EditText_DoCommand (
- EditText* self,
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo (self);
- break;
- case cmdCut:
- DoCut (self);
- break;
- case cmdCopy:
- DoCopy (self);
- break;
- case cmdPaste:
- DoPaste (self);
- break;
- case cmdClear:
- DoClear (self);
- break;
- case cmdSelectAll:
- DoSelectAll (self);
- break;
- case cmdShowClipboard:
- DoShowClipboard (self);
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-